package com.cw.jeeyt.service.converter.security;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.security.SecurityResourceBo;
import com.cw.jeeyt.dao.model.security.SecurityResourceDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 资源信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:01:34
 */
public class SecurityResourceConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SecurityResourceBo do2Bo(SecurityResourceDo model) {
        if (model == null) {
            return null;
        }
        SecurityResourceBo bo = new SecurityResourceBo();
        bo.setId(model.getId());
        bo.setResName(model.getResName());
        bo.setResTitle(model.getResTitle());
        bo.setResIcon(model.getResIcon());
        bo.setResOrder(model.getResOrder());
        bo.setResUrl(model.getResUrl());
        bo.setParentId(model.getParentId());
        bo.setComment(model.getComment());
        bo.setIsMenu(model.getIsMenu());
        bo.setIsView(model.getIsView());
        bo.setBtnList(model.getBtnList());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SecurityResourceDo bo2Do(SecurityResourceBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityResourceDo model = new SecurityResourceDo();
        model.setId(bo.getId());
        model.setResName(bo.getResName());
        model.setResTitle(bo.getResTitle());
        model.setResIcon(bo.getResIcon());
        model.setResOrder(bo.getResOrder());
        model.setResUrl(bo.getResUrl());
        model.setParentId(bo.getParentId());
        model.setComment(bo.getComment());
        model.setIsMenu(bo.getIsMenu());
        model.setIsView(bo.getIsView());
        model.setBtnList(bo.getBtnList());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SecurityResourceBo> doList2BoList(List<SecurityResourceDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityResourceConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SecurityResourceDo> boList2DoList(List<SecurityResourceBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityResourceConverter::bo2Do));
    }
}